package cn.wolfcode.utils;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;
import java.util.Map;

public class JwtUtils {
    private static String signingKey = "wolfcode";
    private static Long expire = 3600 * 1000 * 24L;
    /**
     *生成jwt的方法
     */
    public static String generateToken(Map<String, Object> claims) {
            return Jwts.builder().addClaims(claims)
                    .signWith(SignatureAlgorithm.HS512, signingKey)
                    .setExpiration(new Date(System.currentTimeMillis() + expire))
                    .compact();
        }
    /**
     * 解析jwt的方法
     */
    public static Claims parseJwt(String token) {
        return Jwts.parser()
                .setSigningKey(signingKey)
                .parseClaimsJws(token)
                .getBody();
    }

}
